<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>新增活动-添加捐赠书籍</title>
<link rel="icon" href="favicon.ico" type="image/ico">

<link href="/Public/Admin/css/bootstrap.min.css" rel="stylesheet">
<link href="/Public/Admin/css/materialdesignicons.min.css" rel="stylesheet">
<link href="/Public/Admin/js/bootstrap-select/bootstrap-select.css" rel="stylesheet">
<!--标签插件-->
<link rel="stylesheet" href="/Public/Admin/js/jquery-tagsinput/jquery.tagsinput.min.css">
<link href="/Public/Admin/css/style.min.css" rel="stylesheet">
</head>

<body>
<div class="container-fluid p-t-15">
  <div class="col-lg-12">
      <div class="card">
        <header class="card-header"><div class="card-title">步骤</div></header>
        <div class="card-body">
          
          <ul class="nav nav-step nav-fill">
            <li class="nav-item">
              <span>活动基本信息</span>
              <a class="nav-link active" href="#"></a>
            </li>
  
            <li class="nav-item">
              <span>捐赠书籍添加</span>
              <a class="nav-link active" href="#"></a>
            </li>
  
            <li class="nav-item">
              <span>完成</span>
              <a class="nav-link" href="#"></a>
            </li>

          </ul>
        </div>
      </div>
    </div>
  <div class=" row" >
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">
          
          <form action="#" method="post" name="addActivityBook" id="addActivityBook" class="addActivityBook">
			<input type="text" id="id" name="id" class="id" value="<?php echo $activity_id;?>" style="display:none" />
			<div class="form-group col-md-12">
              <label for="sort">书目ID</label>
              <!--<input type="text" class="form-control" id="book_id" name="book_id" value="" />-->
            
           <select class="form-control selectpicker" data-live-search="true" id="book_id" name="book_id">
               <?php foreach($bookArrs as $arr){?>
                <option data-tokens="<?php echo $arr['book_name']?>" value="<?php echo $arr['book_id']?>"><?php echo $arr['book_id']?>:<?php echo $arr['book_name']?></option>
                <?php }?>
              </select>
            </div>
                   
			<div class="form-group col-md-12">
              <label for="sort">书籍名称</label>
              <input type="text" class="form-control" id="book_name" name="book_name" value="" />
            </div>
			<div class="form-group col-md-12">
              <label for="sort">捐赠数量<div class="suggest"></div></label>
              <input type="text" class="form-control" id="book_count" name="book_count" value="" />
            </div>
            <div class="form-group col-md-12">
              <button id="submitbtn" type="submit" class="btn btn-success ajax-post confirm" target-form="addActivityBook">添 加</button>
              <button id="okbtn" type="button" class="btn btn-info" >完成添加</button>
            </div>
          </form>
        </div>
      </div>
    </div>
    
  </div>
  

      <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                
                
                  <div class="card text-white bg-primary">
                    <div class="card-body" id="book_added">
                      <h3>已添加书籍：</h3>
                    </div>
                  </div>
                

            </div>
        </div>
    </div>

  
  
  
</div>
<script type="text/javascript" src="/Public/Admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/Public/Admin/js/popper.min.js"></script>
<script type="text/javascript" src="/Public/Admin/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/Public/Admin/js/perfect-scrollbar.min.js"></script>
<!--下拉菜单-->
<script type="text/javascript" src="/Public/Admin/js/bootstrap-select/bootstrap-select.min.js"></script>
<script type="text/javascript" src="/Public/Admin/js/bootstrap-select/i18n/defaults-zh_CN.min.js"></script>
<!--标签插件-->
<script src="/Public/Admin/js/jquery-tagsinput/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="/Public/Admin/js/main.min.js"></script>
<script type="text/javascript" src="/Public/Admin/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/Public/Admin/js/lyear-loading.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    // 默认
    //$('.selectpicker').selectpicker();
    //$('.dropdown-toggle').dropdown();
    //$('.selectpicker').data('selectpicker', null);
    //$('.selectpicker').find("button:first").remove();
    $('.selectpicker').selectpicker();

});
$("#submitbtn").click(function(){
	var id = $("#id").val();
	var book_id = $("#book_id").val();
	var book_name = $("#book_name").val();
	var book_count = $("#book_count").val();
  $.post("?c=Activity&a=addActivityBook",
  $('#addActivityBook').serialize(),
  function(status){
      if(status==200){
          $.notify({
    		// options
    		message: '活动ID：'+id+'<br>成功新增《'+book_name+'》 '+book_count+'本',
    		//url: '?c=User&a=showUser',
    		target: '_self'
		  },{
    		// settings
    		type: 'info',
    		delay: 5000,
    		placement: {
    		from: "top",
    		align: "right"
    		}
		  });
	//添加到下面
	$("#book_added").append("<p>"+'《'+book_name+'》 '+book_count+'本'+"</p>");
	//清空
	$("#book_id").val("");
	$("#book_name").val("");
	$("#book_count").val("");
      }
      else{
          $.notify({
    		// options
    		message: '失败<br>请检查后重试',
    		//url: '?c=User&a=showUser',
    		//target: '_self'
		  },{
    		// settings
    		type: 'danger',
    		delay: 5000,
    		placement: {
    		from: "top",
    		align: "right"
    		}
		  });
      }
	  
});
//这里return false了就能不刷新了
return false;
});

//点击完成添加
$("#okbtn").click(function(){
    var id = $("#id").val();
    window.location.href="?c=Activity&a=showActivityandBook&id="+id+""
	
});

//下拉框选择
$("#book_id").change(function(){
    var a = $("#book_id option:selected").text();
    var arr = a.split(':');
    for(var i=1;i<arr.length;i++){
        var book_name = arr[i];
        $("#book_name").val(book_name);
    }
    //alert(arr[1]);
	//然后获取最大可捐量（该book_id在book表的已捐量和库存量相加=总量，总数-该书在去向表中的总数=最大可捐量）
	//获取图书ID
	var book_id = $("#book_id").val();
	$.post("?c=Activity&a=getCapacity",
	{'id':book_id},
	function(status){
        //alert(status);
        $(".suggest").html("最大可捐量为："+status);
    });
});


</script>
</body>
</html>